package com.zen.android.sample.main;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.zen.android.sample.R;

import java.util.List;

/**
 * @author zeng
 * @Create at 2017/12/20
 * @Description: .
 */

public class MainSampleAdapter extends RecyclerView.Adapter<MainSampleAdapter.SampleHolder> {

    private Context mContext;
    private List<SampleBean> mList;

    public MainSampleAdapter(Context pContext, List<SampleBean> pList) {
        mContext = pContext;
        mList = pList;
    }

    @Override
    public SampleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.main_sample_list_item,null);
        return new SampleHolder(view);
    }

    @Override
    public void onBindViewHolder(SampleHolder holder, final int position) {
        holder.nameTv.setText(mList.get(position).name);
        holder.nameTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(mContext, mList.get(position).targetCls);
                mContext.startActivity(it);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class SampleHolder extends RecyclerView.ViewHolder {
        TextView nameTv;

        public SampleHolder(View itemView) {
            super(itemView);
            nameTv = (TextView) itemView.findViewById(R.id.main_sample_list_item_tv_name);
        }
    }
}
